package com.web3.management.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 交易日志实体
 */
@Getter
@Setter
@Accessors(chain = true)
@Entity
@Table(name = "trade_logs", indexes = {
        @Index(name = "idx_trade_logs_account", columnList = "account_id"),
        @Index(name = "idx_trade_logs_config", columnList = "account_config_id"),
        @Index(name = "idx_trade_logs_trade_date", columnList = "trade_date")
})
public class TradeLog extends BaseEntity {

    @Column(name = "account_id", nullable = false)
    private Integer accountId;

    @Column(name = "account_config_id")
    private Integer accountConfigId;

    @Column(name = "trade_date", nullable = false)
    private LocalDate tradeDate;

    @Column(name = "trade_time", nullable = false)
    private LocalDateTime tradeTime;

    @Column(name = "direction", length = 20)
    private String direction;

    @Column(name = "planned_amount", precision = 18, scale = 8)
    private BigDecimal plannedAmount;

    @Column(name = "actual_amount", precision = 18, scale = 8)
    private BigDecimal actualAmount;

    @Column(name = "slippage", precision = 18, scale = 8)
    private BigDecimal slippage;

    @Column(name = "status", length = 20)
    private String status;

    @Column(name = "tx_hash", length = 128)
    private String txHash;

    @Lob
    @Column(name = "remark")
    private String remark;

    // ===== v1.3 新增监控字段 =====

    @Column(name = "slippage_rate", precision = 8, scale = 4)
    private BigDecimal slippageRate;

    @Column(name = "is_abnormal")
    private Boolean isAbnormal = false;

    @Column(name = "alert_sent")
    private Boolean alertSent = false;
}
